<?php

/**
 * This is the model class for table "{{ads}}".
 *
 * The followings are the available columns in table '{{ads}}':
 * @property integer $ad_id
 * @property integer $admin_id
 * @property integer $ad_gid
 * @property string $img
 * @property string $link
 * @property string $title
 * @property integer $rank
 * @property string $target
 * @property string $ctime
 * @property string $mtime
 */
class Ads extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Ads the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{ads}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('admin_id, ad_gid, img, link, title, rank, target, ctime', 'required'),
			array('admin_id, ad_gid, rank', 'numerical', 'integerOnly'=>true),
			array('img, link, title', 'length', 'max'=>255),
			array('target', 'length', 'max'=>10),
			array('mtime', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ad_id, admin_id, ad_gid, img, link, title, rank, target, ctime, mtime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ad_id' => 'Ad',
			'admin_id' => 'Admin',
			'ad_gid' => 'Ad Gid',
			'img' => 'Img',
			'link' => 'Link',
			'title' => 'Title',
			'rank' => 'Rank',
			'target' => 'Target',
			'ctime' => 'Ctime',
			'mtime' => 'Mtime',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ad_id',$this->ad_id);
		$criteria->compare('admin_id',$this->admin_id);
		$criteria->compare('ad_gid',$this->ad_gid);
		$criteria->compare('img',$this->img,true);
		$criteria->compare('link',$this->link,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('rank',$this->rank);
		$criteria->compare('target',$this->target,true);
		$criteria->compare('ctime',$this->ctime,true);
		$criteria->compare('mtime',$this->mtime,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}